#ifndef XMLVIEW_H
#define XMLVIEW_H

#include "controls.h"
#include "xmledit.h"
#include "xmlcapture.h"
#include "tuxdocument.h"
#include "observer.h"

namespace view
{
	using design::Observer;
	using design::Observable;
	using doc::TuxDocument;
	using doc::DocNode;
	using win::Splitter;
	using win::StatusWindow;
	using win::Toolbar;
	using win::Window;
	using win::TreeViewItem;
	using win::Tree;
	using win::TreeItem;
	using win::ChildWindow;
	using win::PopupMenu;
	
	
	class TuxTree : public ChildWindow,
                    public Observer
	{
		public:
			static LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
		public:
			void Create(const Window &parent,
	  					const int child_index);
			void OnMove(win::Rect r);
			void OnDestroy();
			void OnContextMenu(int x, int y);
			void OnDelete();  // user chose to delete selected node
			void OnMove(const int id);  
			void OnCopy();
			void OnCut();
			void OnPaste();
			void OnSelChanged(DocNode * pNode, HTREEITEM item);
			// When one of the add items are selected
			void OnContextMenuAdd(unsigned int menuId);
			void Update(Observable*,int aspect);
			HFONT GetTreeFont()
			{
				return _tree.GetFontHandle();
			}
			void MoveSelected(const DocNode::eMoveMethod mm);
		private:
			Tree _tree;
			PopupMenu _contextMenu;  // we need the context menu for dynamic items
			HTREEITEM _oldItem; // used during selection process
			void ReloadTree();
			void ReloadFocusNode();
			void ShowFocusNode();
			void AppendNode(TreeItem &, DocNode *);
			void AppendChildNodes(TreeItem &, DocNode *);
			void BuildContextMenu();
	};

	class XmlView : public win::Window,
 				    public Observer
	{
		public:
			static LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
		private:
			HFONT _textFont; 
			XmlEdit _editor;
			TuxCapture _capture;
			TuxTree _tree;
			StatusWindow _status;
			Splitter _split_vert;
			Splitter _split_hor;
			Toolbar _toolbar;
			void ShowFileName();
			void SetCanSave(const bool value);
		public:
			XmlView();
			~XmlView();
			void OnFileNew(int templateIndex);
			void OnFileOpen();
   			void OnFileOpenTemplate();
			void OnFileSave();
			void OnFileSaveAndPreview();
			void OnFileSaveAs();
   			bool OnFileClose();
   			void OnSetFont();
			void OnRestoreLayout();
			void OnNodeMove(const DocNode::eMoveMethod);
			void OnCreate(const HWND hwnd);
			void OnPaint();
			void OnSize(const int, const int);
			void OnNotify(const int id, const UINT code);
   			void Update(Observable*,int aspect);
	};

	extern XmlView xmlview;
}
#endif 

